package org.wms.minbearwcs.dao.storage.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
import org.wms.minbearwcs.dao.storage.inf.NormalStorageDao;
import org.wms.minbearwcs.entity.Mapper.storage.NormalStorageMapper;
import org.wms.minbearwcs.entity.PO.wcs.storage.NormalStorage;
import org.wms.minbearwcs.entity.PO.wcs.storage.type.NormalPointType;

import java.util.Optional;


@Repository
@RequiredArgsConstructor
public class NormalStorageDaoImpl implements NormalStorageDao {
    private final NormalStorageMapper mapper;


    @Override
    public NormalStorage selectOneNullPalletByType(NormalPointType type) {
        return new LambdaQueryChainWrapper<>(mapper)
                .eq(NormalStorage::getPalletCode,null)
                .eq(NormalStorage::getPointType,type)
                .one();
    }

    @Override
    public String selectLiftRequestGroupByQrCode(String qrCode) {
        Optional<NormalStorage> normalStorage = new LambdaQueryChainWrapper<>(mapper)
                .eq(NormalStorage::getQrCode, qrCode)
                .last("limit 1")
                .oneOpt();
        return normalStorage.map(NormalStorage::getLiftRequestPointGroupCode).orElse(null);
    }

}
